package com.eedi.framework.permission.framework.security;

import cn.hutool.core.util.StrUtil;
import com.eedi.framework.common.exception.util.PreconditionsUtils;
import com.eedi.framework.permission.enums.OrgPermissionErrorCodeConstants;
import com.eedi.framework.security.core.service.OrgPermissionApi;
import com.eedi.framework.permission.service.OrgPermissionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.Set;

/**
 * 权限执行
 * @author 永聚长青
 */
@Service
@Slf4j
public class OrgPermissionApiImpl implements OrgPermissionApi {
    @Resource
    private OrgPermissionService orgPermissionService;
    @Override
    public Set<String> getUserRoleIdListByRoleIds(Collection<String> collection) {
        return orgPermissionService.getUserRoleIdListByRoleId(collection);
    }

    @Override
    public boolean hasAnyPermissions(String s, String... strings) {
        PreconditionsUtils.checkArgument(StrUtil.isNotBlank(s), OrgPermissionErrorCodeConstants.ORG_PERMISSION_USER_INFO_NOT_EXISTS);
        return orgPermissionService.hasAnyPermissions(s,strings);
    }

    @Override
    public boolean hasAnyRoles(String s, String... strings) {
        PreconditionsUtils.checkArgument(StrUtil.isNotBlank(s), OrgPermissionErrorCodeConstants.ORG_PERMISSION_USER_INFO_NOT_EXISTS);
        return orgPermissionService.hasAnyRoles(s,strings);
    }
}
